{% extends "base_for_react.html" %}
{% load seahub_tags i18n %}
{% load render_bundle from webpack_loader %}

{% block extra_ogp_tags %}
<meta property="og:type" content="object" />
<meta property="og:site_name" content="{{ site_name }}">
<meta property="og:url" content="{{ service_url }}{{ file_share_link }}" />
<meta property="og:title" content="{{ file_name }}" />
<meta property="og:image" content="{{ service_url }}{{ MEDIA_URL }}img/file/{{ icon_path_for_ogp }}" />
<meta property="og:description" content="{{ desc_for_ogp }}" />
{% endblock %}

{% block extra_style %}
{% if filetype == 'Markdown' %}
    {% render_bundle 'sharedFileViewMarkdown' 'css' %}
{% elif filetype == 'Text' %}
    {% render_bundle 'sharedFileViewText' 'css' %}
{% elif filetype == 'Image' or filetype == 'XMind' %}
    {% render_bundle 'sharedFileViewImage' 'css' %}
{% elif filetype == 'SVG' %}
    {% render_bundle 'sharedFileViewSVG' 'css' %}
{% elif filetype == 'Video' %}
    {% render_bundle 'sharedFileViewVideo' 'css' %}
{% elif filetype == 'Audio' %}
    {% render_bundle 'sharedFileViewAudio' 'css' %}
{% elif filetype == 'PDF' %}
    <link rel="resource" type="application/l10n" href="{{ MEDIA_URL }}js/pdf/locale/locale.properties" />
    {% render_bundle 'sharedFileViewPDF' 'css' %}
{% elif filetype == 'Document' %}
    <link rel="resource" type="application/l10n" href="{{ MEDIA_URL }}js/pdf/locale/locale.properties" />
    {% render_bundle 'sharedFileViewDocument' 'css' %}
{% elif filetype == 'SpreadSheet' %}
    {% render_bundle 'sharedFileViewSpreadsheet' 'css' %}
{% elif filetype == 'Unknown' %}
    {% render_bundle 'sharedFileViewUnknown' 'css' %}
{% endif %}
{% if not permissions.can_download %}
<style type="text/css">
body {
  user-select:none;
}
@media print {
  html {
    display:none;
  }
}
</style>
{% endif %}
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
  window.shared = {
    pageOptions: {
      repoID: '{{ repo.id }}',
      filePath: '{{ path|escapejs }}',
      sharedToken: '{{ shared_token }}',
      trafficOverLimit: {% if traffic_over_limit %}true{% else %}false{% endif %},
      fileName: '{{ file_name|escapejs }}',
      fileSize: {{ file_size }},
      rawPath: '{{ raw_path|escapejs }}',
      sharedBy: '{{ shared_by|email2nickname|escapejs }}',
      siteName: '{{ site_name }}',
      enableWatermark: {% if enable_watermark %}true{% else %}false{% endif %},
      canDownload: {% if permissions.can_download %}true{% else %}false{% endif %},
      fileContent: '{{ file_content|escapejs }}',
      err: {% if err %}'{{ err }}'{% else %}''{% endif %},
      fileType: '{{ filetype }}',
      fileExt: '{{ fileext }}',
      commitID: '{{ current_commit.id }}' || '{{ repo.head_cmmt_id }}',
      enableShareLinkReportAbuse: {% if enable_share_link_report_abuse %}true{% else %}false{% endif %},
      
      // for 'view file in shared dir'
      {% if zipped %}
      zipped: (function() {
        var list = [];
        {% for name, path in zipped %}
        list.push({
          'name': '{{ name|escapejs }}',
          'path': '{{ path|escapejs }}'
        });
        {% endfor %}
        return list;
      })(),
      {% endif %}
      prevImgPath: {% if img_prev %}'{{ img_prev|escapejs }}'{% else %}''{% endif %},
      nextImgPath: {% if img_next %}'{{ img_next|escapejs }}'{% else %}''{% endif %}
    }
  };
</script>
{% if filetype == 'Markdown' %}
    {% render_bundle 'sharedFileViewMarkdown' 'js' %}
{% elif filetype == 'Text' %}
    {% render_bundle 'sharedFileViewText' 'js' %}
{% elif filetype == 'Image' or filetype == 'XMind' %}
    {% render_bundle 'sharedFileViewImage' 'js' %}
{% elif filetype == 'SVG' %}
    {% render_bundle 'sharedFileViewSVG' 'js' %}
{% elif filetype == 'Video' %}
    {% render_bundle 'sharedFileViewVideo' 'js' %}
{% elif filetype == 'Audio' %}
    {% render_bundle 'sharedFileViewAudio' 'js' %}
{% elif filetype == 'PDF' %}
    {% render_bundle 'sharedFileViewPDF' 'js' %}
    <script type="text/javascript">
    var sf_file_url = '{{ raw_path|escapejs }}';
    var sf_pdfworkerjs_url = '{{MEDIA_URL}}js/pdf/pdf.worker.min.js';
    var sf_pdf_images_path = '{{MEDIA_URL}}js/pdf/images/';
    var sf_pdf_cmaps_path = '{{MEDIA_URL}}js/pdf/cmaps/';
    </script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/pdf/pdf.min.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/pdf/viewer.js"></script>
{% elif filetype == 'Document' %}
    {% render_bundle 'sharedFileViewDocument' 'js' %}
    <script type="text/javascript">
      var commit_id = '{{ current_commit.id }}' || '{{ repo.head_cmmt_id }}';
      var sf_file_url = '{{ SITE_ROOT }}office-convert/static/{{ repo.id }}/' + commit_id + '{{ path|urlencode }}/fake.pdf?token={{shared_token}}';
      var sf_pdfworkerjs_url = '{{MEDIA_URL}}js/pdf/pdf.worker.min.js';
      var sf_pdf_images_path = '{{MEDIA_URL}}js/pdf/images/';
      var sf_pdf_cmaps_path = '{{MEDIA_URL}}js/pdf/cmaps/';
    </script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/pdf/pdf.min.js"></script>
{% elif filetype == 'SpreadSheet' %}
    {% render_bundle 'sharedFileViewSpreadsheet' 'js' %}
{% elif filetype == 'Unknown' %}
    {% render_bundle 'sharedFileViewUnknown' 'js' %}
{% endif %}
{% endblock %}
